package com.jman.resident.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jman.resident.dao.ResidentDao;
import com.jman.resident.domain.Resident;
import com.jman.resident.dto.PageBean;
import com.jman.resident.dto.PageInfo;
import com.jman.resident.service.IResidentService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResidentServiceImpl extends ServiceImpl<ResidentDao, Resident> implements IResidentService {
    public PageBean<Resident> getInfoByPage(PageInfo pageInfo) {
        Integer pageSize = pageInfo.getPageSize();
        Integer currentPage = pageInfo.getCurrentPage();
        IPage<Resident> page = new Page(currentPage, pageSize);

        //得到列表值
        IPage<Resident> residentIPage = page(page, null);
        List<Resident> records = residentIPage.getRecords();
        //得到总数
        long total = residentIPage.getTotal();

        PageBean<Resident> pageBean = new PageBean<>();
        pageBean.setRows(records);
        pageBean.setTotalCount(total);
        return pageBean;
    }
}
